#include "QmlLoader.h"

//---------------------------------------------------------
QmlLoader::QmlLoader(QDeclarativeEngine &engine) :
    mEngine(&engine),
    mNodeComp(mEngine, QUrl::fromLocalFile("qml/Node.qml")),
    mItemComp(mEngine, QUrl::fromLocalFile("qml/NodeItem.qml"))
{}

//---------------------------------------------------------
QDeclarativeItem* QmlLoader::createNode(QDeclarativeItem *parent)
{
    QDeclarativeItem* result = qobject_cast<QDeclarativeItem*>(mNodeComp.create());
    if ( result )
        result->setParentItem(parent);
    else
        qDebug() << "cant load Node";
    return result;
}

//---------------------------------------------------------
QDeclarativeItem* QmlLoader::createItem(QDeclarativeItem *parent)
{
    QDeclarativeItem *result = qobject_cast<QDeclarativeItem*>(mItemComp.create());
    if ( result )
    {
        result->setParent(parent);
        result->setParentItem(parent);
    }
    else
        qDebug() << "cant load point";
    return result;
}
